package com.example.course.controller;

import com.example.course.bean.Teacher;
import com.example.course.service.TeacherService;
import com.example.course.vo.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
public class TeacherController {
    @Resource
    private TeacherService teacherService;

    @ResponseBody
    @RequestMapping("/course/showTeachers")
    public Result showTeachers() {
        return new Result(teacherService.getTeachers());
    }

    @ResponseBody
    @RequestMapping("/course/updateTeacher")
    public Result updateTeacher(Teacher teacher) {
        int i = teacherService.updateTeacher(teacher);
        if (i == 0) {
            return Result.fail();
        }else {
            return Result.success();
        }

    }
    @ResponseBody
    @RequestMapping("/course/deleteTeacher/{id}")
    public Result deleteTeacher(@PathVariable int id) {
        int i = teacherService.deleteTeacher(id);
        if (i == 0) {
            return Result.fail();
        }else {
            return Result.success();
        }

    }
    @ResponseBody
    @RequestMapping("/course/insTeacher")
    public Result insertTeacher(Teacher teacher) {
        int i = teacherService.insertTeacher(teacher);
        if (i == 0) {
            return Result.fail();
        }else {
            return Result.success();
        }

    }


}
